package com.backstage;


import com.backstage.service.SysDictionaryService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Map;

@SpringBootApplication
@EnableTransactionManagement
@MapperScan("com.backstage.mapper")
@EnableCaching
public class BackstageApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(BackstageApplication.class, args);
        run.addApplicationListener(e -> {
            SysDictionaryService dictionaryService = (SysDictionaryService) run.getBean("SysDictionaryService");
            Map<String, Map<String, String>> data = dictionaryService.load();
            if (dictionaryService.getData().size() == 0) {
                dictionaryService.setData(data);
            }
        });
    }

}
